const path = require("path");
const buildName = "build";
const HtmlWebpackPlugin = require("html-webpack-plugin");
const VueLoaderPlugin = require("vue-loader/lib/plugin");
const { CleanWebpackPlugin } = require("clean-webpack-plugin");
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
// const Webpack = require("webpack");
module.exports = {
    //打包模式
    mode: "development",
    //入口文件
    entry: "./main.js",
    //输出文件名和输出路径
    output: {
        filename: "bundle_[hash:4].js",
        path: path.join(__dirname, buildName),
    },
    //特殊文件匹配格式和加载器
    module:{
        rules:[
            {
                test: /\.vue$/,
                loader: "vue-loader"
            },
            {
                test: /\.css$/,
                use: [MiniCssExtractPlugin.loader,"css-loader"]
            },
            {
                test: /\.less$/,
                use: [MiniCssExtractPlugin.loader,"css-loader","less-loader"]
            }
        ]
    },
    plugins: [

        new CleanWebpackPlugin(),
        //自动生成html文件
        new HtmlWebpackPlugin({
            //网页标题
            title: "vue + webpack"
        }),
        new VueLoaderPlugin(),
        //打包时生成css文件
        new MiniCssExtractPlugin({
            filename: "style.css"
        })
        
        //热部署
        // new Webpack.HotModuleReplacementPlugin()
        
    ]
}